Skip to content

Conversation

@delorenj
Copy link

@delorenj delorenj commented Jan 3, 2025

Add support for passing environment variables via command line arguments with both long form (--envVars) and short form (-e) options.

Motivation and Context

When running MCP servers, users often need to pass environment variables for configuration (API keys, debug flags, etc.). Currently, this requires setting environment variables before running the inspector or modifying the system environment. This change allows for more flexible and explicit environment variable configuration directly through command line arguments.

How Has This Been Tested?

Added comprehensive test suite in server/src/__tests__/env-vars.test.ts covering:

  • Single variable with long flag (--envVars)
  • Single variable with short flag (-e)
  • Multiple environment variables
  • Empty environment variables list
  • Environment variable object merging

All tests pass locally. Example usage tested:

npx @modelcontextprotocol/inspector build/index.js --envVars API_KEY=abc123 -e DEBUG=true

- Update @types/node to version 22.10.5
- Update spawn-rx to version 5.1.1
- Add @types/node, @types/shell-quote, and spawn-rx as dev dependencies
- Enhance createTransport function to support multiple environment variable sources
- Implement command-line argument parsing for environment variables
- Improve environment variable merging logic in transport creation
- Implement parsing of environment variables from command line arguments
- Add Jest configuration for TypeScript testing
- Create test suite for environment variable handling
- Update README with instructions for passing environment variables
- Add test coverage information to README
@delorenj delorenj marked this pull request as draft January 3, 2025 19:10
- Remove Jest configuration and test files
- Remove Jest and ts-jest dev dependencies
- Remove test script from package.json
- Update environment variable handling in index.ts
@jspahrsummers
Copy link
Member

Superseded by #124, AFAICT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants